#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.dirname(File.realpath($PROGRAM_NAME))))

require "#{LKP_SRC}/lib/string"
require "#{LKP_SRC}/lib/assert"
require "#{LKP_SRC}/lib/tests/stats"

stats = LKP::Stats.new

while (line = $stdin.gets)
  line = line.resolve_invalid_bytes

  case line
  when /avocado run (\S+)/
    # 2022-11-07 19:02:32 avocado run /lkp/benchmarks/avocado/examples/tests/gdbtest.py:GdbTest.test_existing_commands_raw --job-timeout 30
    # 2024-09-29 08:20:32 avocado run --vt-config /lkp/benchmarks/avocado/data/avocado-vt/backends/qemu/cfg/tdx_temp.cf
    run_option = File.basename($1)
  when /\(\d+\/\d+\) (\S+):\s+(\w+)/
    # (1/1) type_specific.lkvs.boot_check.vm.16G.16_cpu:  PASS (36.35 s)
    # (1/1) /lkp/benchmarks/avocado/examples/tests/gdbtest.py:GdbTest.test_existing_commands_raw:  PASS (0.43 s)
    assert run_option == File.basename($1), "test case '#{run_option}' not equal to '#{File.basename($1)}'" unless run_option == '--vt-config'

    test_case = File.basename($1)

    test_status = $2.downcase
    next if test_status == 'started'

    stats.add test_case.to_s, test_status
  end
end

stats.dump
